
package com.yimixian.app.fragment;

import com.yimixian.app.R;
import com.yimixian.app.activity.YMXMainActivity;
import com.yimixian.app.common.Constants;
import com.yimixian.app.mvp.presenter.UnloginPresenter;
import com.yimixian.app.mvp.view.UnloginMvpView;
import com.yimixian.app.user.UserRegistrationActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class UnloginFragment extends Fragment implements UnloginMvpView {

    @InjectView(R.id.iv_no_login)
    ImageView mIvNoLogin;
    @InjectView(R.id.tv_login)
    TextView mTvLogin;
    @InjectView(R.id.rl_login)
    RelativeLayout mRlLogin;
    UnloginPresenter mPresenter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        int tab = getArguments().getInt(YMXMainActivity.TAB_INDEX_KEY, -1);
        View view = inflater.inflate(R.layout.fragment_unlogin, container, false);
        ButterKnife.inject(this, view);

        mPresenter = new UnloginPresenter();
        mPresenter.attachView(this);
        mPresenter.showData(tab);

        mRlLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), UserRegistrationActivity.class);
                startActivityForResult(intent, Constants.USER_REGISTRATION_REQUEST_CODE);
            }
        });
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mPresenter.detachView();
    }

    @Override
    public void showUnlogin() {
        mTvLogin.setText(getString(R.string.order_no_login_tips));
    }
}
